package org.projsquirrel;


import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
 
public class Attachment extends Activity {
        Button send,attachpic;
        EditText address, subject, emailtext;
        TextView picuri;
        Uri currImgURI;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.attachpic);
        send=(Button) findViewById(R.id.emailsendbutton);
        attachpic = (Button) findViewById(R.id.attachpicbutton);
        address=(EditText) findViewById(R.id.emailaddress);
        subject=(EditText) findViewById(R.id.emailsubject);
        emailtext=(EditText) findViewById(R.id.emailtext);
        picuri=(TextView) findViewById(R.id.picuri);
        this.setTitle("Share Comments");
        send.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            // TODO Auto-generated method stub
                  final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);                               
                  emailIntent.setType("plain/text");                                
                  emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});                              
                  emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());                               
                  emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());
                  if(currImgURI!=null)
                	  emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,currImgURI );
                  Attachment.this.startActivity(Intent.createChooser(emailIntent, "Sending email..."));
            }
        });
        
        attachpic.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		 Intent i = new Intent();
        		 i.setType("image/*");
        		 i.setAction(Intent.ACTION_GET_CONTENT);
        	     startActivityForResult(Intent.createChooser(i,"Select Picture"), 1);
        	    }
        });
      }
    
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	super.onActivityResult(requestCode, resultCode, data);
      if(resultCode == RESULT_OK){  
                if(requestCode == 1) {
                	currImgURI = data.getData();
                	picuri.setText(currImgURI.toString());
                }
            }
        }
    
    
}